package web;

import factory.ServiceFactory;
import pojo.vo.Result;
import service.RoleService;
import service.RoleServiceImpl;
import utils.BaseController;

import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "RoleServlet", value = "/role/*")
public class RoleServlet extends BaseServlet {
    RoleService service = (RoleService)ServiceFactory.getBean("roleService");

    /**
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String[] split = request.getRequestURI().split("/");
        System.out.println("====");
        System.out.println("参数:"+ Arrays.toString(split));
        String method = split[split.length-1];
        switch (method){
            case "findAllRolesName":findAllRolesName(request,response);
        }

    }

    */
    private void findAllRolesName(HttpServletRequest request, HttpServletResponse response) {
        Result allRoles = service.findAllRoles();
        try {
            BaseController.printResult(response,allRoles);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
